package jrain.fw.script.expression;

import java.util.Map;

import jrain.fw.script.resolver.VariableResolver;
import jrain.fw.script.tools.ELException;
import jrain.fw.script.tools.Logger;
 
public class NamedValue extends Expression {
	// -------------------------------------
	// Constants
	// -------------------------------------

	// -------------------------------------
	// Properties
	// -------------------------------------
	// property name

	String mName;

	public String getName() {
		return mName;
	}

	// -------------------------------------

	/**
	 * Constructor
	 */
	public NamedValue(String pName) {
		mName = pName;
	}

	// -------------------------------------
	// Expression methods
	// -------------------------------------

	/**
	 * Returns the expression in the expression language syntax
	 */
	public String getExpressionString() {
		return StringLiteral.toIdentifierToken(mName);
	}

	// -------------------------------------

	/**
	 * Evaluates by looking up the name in the VariableResolver
	 */
	public Object evaluate(Object pContext, VariableResolver pResolver, Map<Object, Object> functions, String defaultPrefix, Logger pLogger)
			throws ELException {
		if (pResolver == null) {
			return null;
		} else {
			return pResolver.resolveVariable(mName, pContext);
		}
	}

	// -------------------------------------
}
